package com.example.smartcity_40.lawyer;

import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;

import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.example.smartcity_40.R;
import com.example.smartcity_40.lawyer.bean.AddLaeyerSeekBean;
import com.example.smartcity_40.lawyer.bean.SeekdetailBean;
import com.example.smartcity_40.lawyer.bean.UserSeekBean;
import com.example.smartcity_40.tool.Tool;
import com.google.gson.Gson;

import kotlin.Unit;
import kotlin.jvm.functions.Function1;

public class SeekDetailsActivity extends AppCompatActivity {

    private SeekDetailsActivity context;
    private ImageView avatarUrl;
    private TextView name;
    private TextView legalExpertiseName;
    private TextView serviceTimes;
    private TextView favorableCount;
    private String seekdetails;
    private Tool tool;
    private TextView content;
    private TextView start;
    private TextView contenttype;
    private TextView phone;
    private UserSeekBean.RowsBean rowsBean;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_seek_details);
        context = this;
        initview();
        seekdetailmethod();
    }

    private void seekdetailmethod() {
        Integer id = rowsBean.getId();
        if(id==null){
            return;
        }
        tool.send("/prod-api/api/lawyer-consultation/legal-advice/"+id,
                Tool.GET,
                null,
                true,
                SeekdetailBean.class,
                new Function1<SeekdetailBean, Unit>() {
                    @Override
                    public Unit invoke(SeekdetailBean seekdetailBean) {
                        if (seekdetailBean.getCode() == 200) {
                            initlawyer(seekdetailBean.getData());
                        }
                        return null;
                    }
                });
    }
    private void initlawyer(SeekdetailBean.DataBean data) {
        if(data==null){
            return;
        }

        String dataName = data.getContent();
        if(!TextUtils.isEmpty(dataName)){
            content.setText(dataName);
        }

        String dataState = data.getState();
        if("0".equals(dataState)){
            start.setText("未处理");
        }else if("1".equals(dataState)){
            start.setText("已处理");
        }

        String dataPhone = data.getPhone();
        if(!TextUtils.isEmpty(dataPhone)){
            phone.setText(dataPhone);
        }



    }

    private void initview() {
        ImageView back = findViewById(R.id.back);


        content = findViewById(R.id.content);
        start = findViewById(R.id.start);
        contenttype = findViewById(R.id.contenttype);
        phone = findViewById(R.id.phone);
        TextView submit = findViewById(R.id.submit);

        avatarUrl = findViewById(R.id.avatarUrl);
        name = findViewById(R.id.name);
        legalExpertiseName = findViewById(R.id.legalExpertiseName);
        serviceTimes = findViewById(R.id.serviceTimes);
        tool = new Tool(context);



        Intent intent = getIntent();
        seekdetails = intent.getStringExtra("seekdetails");
        Gson gson = new Gson();
        rowsBean = gson.fromJson(seekdetails, UserSeekBean.RowsBean.class);

        legalExpertiseName.setText(rowsBean.getLegalExpertiseName());
        name.setText(rowsBean.getLawyerName());
        serviceTimes.setText(rowsBean.getCreateTime());
        String[] split = rowsBean.getImageUrls().split(",");
        Glide.with(context).load(Tool.url+split[1])
                .error(R.drawable.waimai)
                .into(avatarUrl);

        back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                context.finish();
            }
        });

        submit.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(context, EvaluatelawyerActivity.class);
                intent.putExtra("seekdetails",String.valueOf(rowsBean.getId()));
                context.startActivity(intent);
            }
        });

    }
}